package cn.cloud.all.security.oauth2.provider;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class CreateRequestUtil {

    public static OAuth2Request createOAuth2Request(ClientDetails client, Map<String, String> requestParameters, Set<String> scope, String grantType) {
        HashMap<String, String> modifiable = new HashMap<>(requestParameters);
        // Remove password if present to prevent leaks
        modifiable.remove("password");
        modifiable.remove("client_secret");
        // Add grant type so it can be retrieved from OAuth2Request
        modifiable.put("grant_type", grantType);
        return new OAuth2Request(modifiable, client.getClientId(), client.getAuthorities(), true, scope, client.getResourceIds(), null, null, null);
    }
}
